package com.dev.bbs.service.impl;

import java.util.List;
import com.dev.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dev.bbs.mapper.BbsMentLikeMapper;
import com.dev.bbs.domain.BbsMentLike;
import com.dev.bbs.service.IBbsMentLikeService;

/**
 * 帖子评论点赞Service业务层处理
 * 
 * @author dev
 * @date 2019-09-23
 */
@Service
public class BbsMentLikeServiceImpl implements IBbsMentLikeService
{
    @Autowired
    private BbsMentLikeMapper bbsMentLikeMapper;

    /**
     * 查询帖子评论点赞
     * 
     * @param likeId 帖子评论点赞ID
     * @return 帖子评论点赞
     */
    @Override
    public BbsMentLike selectBbsMentLikeById(Long likeId)
    {
        return bbsMentLikeMapper.selectByPrimaryKey(likeId);
    }

    /**
     * 查询帖子评论点赞列表
     * 
     * @param bbsMentLike 帖子评论点赞
     * @return 帖子评论点赞
     */
    @Override
    public List<BbsMentLike> selectBbsMentLikeList(BbsMentLike bbsMentLike)
    {
        return bbsMentLikeMapper.select(bbsMentLike);
    }

    /**
     * 新增帖子评论点赞
     * 
     * @param bbsMentLike 帖子评论点赞
     * @return 结果
     */
    @Override
    public int insertBbsMentLike(BbsMentLike bbsMentLike)
    {
        if (liked(bbsMentLike.getMentId(), bbsMentLike.getUserId())) return 0;
        bbsMentLike.setCreateTime(DateUtils.getNowDate());
        return bbsMentLikeMapper.insertSelective(bbsMentLike);
    }

    /**
     * 修改帖子评论点赞
     * 
     * @param bbsMentLike 帖子评论点赞
     * @return 结果
     */
    @Override
    public int updateBbsMentLike(BbsMentLike bbsMentLike)
    {
        bbsMentLike.setUpdateTime(DateUtils.getNowDate());
        return bbsMentLikeMapper.updateByPrimaryKeySelective(bbsMentLike);
    }

    /**
     * 删除帖子评论点赞对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteBbsMentLikeByIds(String ids)
    {
        return bbsMentLikeMapper.deleteByIds(ids);
    }

    /**
     * 删除帖子评论点赞信息
     * 
     * @param likeId 帖子评论点赞ID
     * @return 结果
     */
    @Override
    public int deleteBbsMentLikeById(Long likeId)
    {
        return bbsMentLikeMapper.deleteByPrimaryKey(likeId);
    }

    /**
     * 检查评论是否已经点赞
     * @param mentId
     * @param userId
     * @return
     * @author zmr
     */
    @Override
    public boolean liked(long mentId, long userId)
    {
        return bbsMentLikeMapper.selectCount(new BbsMentLike().setMentId(mentId).setUserId(userId)) > 0;
    }
}
